package com.honeyms.project.blog.blogrecommend.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.honeyms.framework.aspectj.lang.annotation.Log;
import com.honeyms.framework.aspectj.lang.enums.BusinessType;
import com.honeyms.project.blog.blogrecommend.domain.BlogRecommend;
import com.honeyms.project.blog.blogrecommend.service.IBlogRecommendService;
import com.honeyms.framework.web.controller.BaseController;
import com.honeyms.framework.web.domain.AjaxResult;
import com.honeyms.common.utils.poi.ExcelUtil;
import com.honeyms.framework.web.page.TableDataInfo;

/**
 * 帖子推荐统计Controller
 * 
 * @author honeyms
 * @date 2020-12-30
 */
@Controller
@RequestMapping("/blog/blogrecommend")
public class BlogRecommendController extends BaseController
{
    private String prefix = "blog/blogrecommend";

    @Autowired
    private IBlogRecommendService blogRecommendService;

    @RequiresPermissions("blog:blogrecommend:view")
    @GetMapping()
    public String blogrecommend()
    {
        return prefix + "/blogrecommend";
    }

    /**
     * 查询帖子推荐统计列表
     */
    @RequiresPermissions("blog:blogrecommend:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BlogRecommend blogRecommend)
    {
        startPage();
        List<BlogRecommend> list = blogRecommendService.selectBlogRecommendList(blogRecommend);
        return getDataTable(list);
    }

    /**
     * 导出帖子推荐统计列表
     */
    @RequiresPermissions("blog:blogrecommend:export")
    @Log(title = "帖子推荐统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BlogRecommend blogRecommend)
    {
        List<BlogRecommend> list = blogRecommendService.selectBlogRecommendList(blogRecommend);
        ExcelUtil<BlogRecommend> util = new ExcelUtil<BlogRecommend>(BlogRecommend.class);
        return util.exportExcel(list, "blogrecommend");
    }

    /**
     * 新增帖子推荐统计
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存帖子推荐统计
     */
    @RequiresPermissions("blog:blogrecommend:add")
    @Log(title = "帖子推荐统计", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BlogRecommend blogRecommend)
    {
        return toAjax(blogRecommendService.insertBlogRecommend(blogRecommend));
    }

    /**
     * 修改帖子推荐统计
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        BlogRecommend blogRecommend = blogRecommendService.selectBlogRecommendById(id);
        mmap.put("blogRecommend", blogRecommend);
        return prefix + "/edit";
    }

    /**
     * 修改保存帖子推荐统计
     */
    @RequiresPermissions("blog:blogrecommend:edit")
    @Log(title = "帖子推荐统计", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BlogRecommend blogRecommend)
    {
        return toAjax(blogRecommendService.updateBlogRecommend(blogRecommend));
    }

    /**
     * 删除帖子推荐统计
     */
    @RequiresPermissions("blog:blogrecommend:remove")
    @Log(title = "帖子推荐统计", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(blogRecommendService.deleteBlogRecommendByIds(ids));
    }
}
